var overviewApp;
$(function() {
	overviewApp = {
		init : function() {
			this.$subPage = $('.sub-page');
			this.bind();
		},
		bind : function() {
			$(document).on('scroll', $.proxy(this.scrollMonitor, this));
			this.$subPage.on('click', '#quikey ul li', $.proxy(this.quikeyClick, this));
		},
		//quikey导航条点击事件
		quikeyClick: function (e) {
	    	if ($('html').is(':animated')) {
	    		return;
	    	}
	    	var that = this;
	    	var $this = $(e.currentTarget);
	    	$this.addClass('active').siblings('li').removeClass('active');
	    	var index = $this.index();
	    	var panelId = $this.data("panelId");
	    	var top = $('#' + panelId).offset().top; // - ($('.flit-box').height() + $('.current-location').height());
	    	$(document).off('scroll');
	    	$('html,body').animate({scrollTop: top}, 500, function () {
	    		$(document).on('scroll', $.proxy(that.scrollMonitor, this));
	    	});
	    },
		  //滚动监控导航条指向
	    scrollMonitor: function () {
	    	var arr = [];
	    	var htmlTop = $(document).scrollTop();
	    	$.each($('div.panel'), function () {
	    		var boxTop = $(this).offset().top// - ($('.flit-box').height() + $('.current-location').height());
	    		if (htmlTop < boxTop) {
	    			var id = $(this).attr("id");
	    			var index = 0;
	    			$.each($('#quikey ul li'), function () {
	    				if (id == $(this).data("panelId")) {
	    					index = $(this).index() - 1;
	    				}
	    			});
	    			if (index < 0) {
	    				index = 0;
	    			}
	    			$('#quikey ul li').eq(index).addClass('active').siblings().removeClass('active');
	    			return false;
	    		}else {
	    			if ($(this).attr("id") == $('#quikey ul li:last-child').data("panelId")) {
	    				$('#quikey ul li:last-child').addClass('active').siblings().removeClass('active');
	    			}
	    		}
	    	});
	    },
	    
	    reInit: function(options) {
	    	if (options && options.parts) {
	    		$("#quikey ul").html("");
	    		$.each(options.parts, function(i, p){
	    			$("#quikey ul").append('<li data-panel-id="' + p.id + '"><a href="javascript: void(0);">' + p.title + '</a></li>');
	    		});
	    		
	    		$("#quikey ul li:first-child").addClass('active')
	    		$("#quikey").show();
	    	}
	    },
	    
	    destory: function() {
	    	$("#quikey ul").html("");
	    	$("#quikey").hide();
	    }
	};

	overviewApp.init();
});